<template>
  <div class="homewrap">
    <div class="lh-wrap">
      <div  class="chanpinshang-list-titleName">
        授权码订单
      </div>
      <ac-search :proinfo="proinfo" ref="arch"></ac-search>
      <input class="proNewAdd" type="button" @click="handleearch(0)" value="搜索" />
      <input class="Red proNewAdd" type="button" @click="handleReset" value="重置" />
      <ac-table :proinfo="proinfo"></ac-table>
      <ac-pagination :proinfo="proinfo" ref="prolistPagin"></ac-pagination>
    </div>
  </div>
</template>

<script>
import Qs from 'qs'
import AcTable from './components/AcTable'
import AcPagination from './components/AcPagination'
import AcSearch from './components/AcSearch'
import request from '@/utils/request.js'
export default {
  name: 'authcode',
  components: {
    AcTable,
    AcPagination,
    AcSearch
  },
  data () {
    return {
      proinfo: []
    }
  },
  methods: {
    change (val) {
      var st = ''
      switch (val) {
        case '待付款':
          st = 1
          break
        case '待制码':
          st = 2
          break
        case '制码中':
          st = 3
          break
        case '待邮寄':
          st = 6
          break
        case '已完成':
          st = 7
          break
        case '已关闭':
          st = 8
          break
        case '待确认':
          st = 9
          break
      }
      return st
    },
    getOrdliset () {
      request.getOrList({
        params: {
          p: 1,
          size: 10
        },
        paramsSerializer: function (params) {
          return Qs.stringify(params, {arrayFormat: 'brackets'})
        }
      }).then(res => {
        this.proinfo = res.list
        this.$refs['prolistPagin'].total = res.total
      }).catch(err => console.log(err))
    },
    handleReset () {
      this.$refs['arch'].formPro.checkedOrder = ''
      this.$refs['arch'].formPro.checkedSqip = ''
      this.$refs['arch'].formPro.checkdeBsqname = ''
      this.$refs['arch'].formPro.checkdeMd = ''
      this.$refs['arch'].formPro.goodName = ''
      this.$refs['arch'].formPro.startDate = ''
      this.$refs['arch'].formPro.endDate = ''
      this.$refs['prolistPagin'].currentPage1 = 1
      this.getOrdliset()
    },
    resetData (time) {
      let d = new Date(time)
      let month = d.getMonth() + 1
      let day = d.getDate()
      if (month < 10) {
        month = '0' + month
      }
      if (day < 10) {
        day = '0' + day
      }
      var youWant = d.getFullYear() + '-' + month + '-' + day
      return youWant
    },
    handleearch (val) {
      var page = ''
      if (val === 0) {
        this.$refs['prolistPagin'].currentPage1 = 1
        page = 1
      } else {
        page = val
      }
      var se1 = this.$refs['arch'].formPro.checkedOrder
      if (!se1) {
        se1 = ''
      }
      var bsq = this.$refs['arch'].formPro.checkedSqip
      var time = ''
      var time1 = ''
      if (this.$refs['arch'].formPro.endDate) {
        time = this.resetData(this.$refs['arch'].formPro.endDate)
      }
      if (this.$refs['arch'].formPro.startDate) {
        time1 = this.resetData(this.$refs['arch'].formPro.startDate)
      }
      var ps = {
        code_segment: this.$refs['arch'].formPro.checkdeMd,
        endDate: time,
        good_name: this.$refs['arch'].formPro.goodName,
        merchant_name: this.$refs['arch'].formPro.checkdeBsqname,
        opus_name: bsq,
        p: page,
        size: 10,
        startDate: time1,
        stauts: this.change(se1)
      }
      var fil1 = this.proinfo.filter(item => {
        var st = ''
        switch (item.status) {
          case 1:
            st = '待付款'
            break
          case 2:
            st = '待制码'
            break
          case 3:
            st = '制码中'
            break
          case 4:
            st = '生产中'
            break
          case 5:
            st = '印刷中'
            break
          case 6:
            st = '已邮寄'
            break
          case 8:
            st = '已关闭'
            break
        }
        return (st === se1)
      })
      this.proinfo = fil1
      request.getOrList({
        params: ps
      }).then(res => {
        this.proinfo = res.list
        this.$refs['prolistPagin'].total = res.total
      })
    }
  },
  mounted () {
    this.handleearch()
  }
}
</script>

<style lang="stylus" scoped>
@import '~styles/varibles.styl'
.homewrap
  padding 20px 20px 5px
  .lh-wrap
    min-width 960px
    box-sizing border-box
    background-color #fff
    padding 30px
    box-shadow 0px 2px 5px #e5e6ec
    .proNewAdd
      display inline-block
      margin 0 0 0 100px
      margin-bottom 27px
      width 90px
      height 36px
      line-height 36px
      text-align center
      background-color $baseColor
      font-size 14px
      font-weight 600
      color #fff
      border-radius 4px
      cursor pointer
    .Red
      margin 0 0 0 10px
      display inline-block
      background-color white
      border 1px solid #f2f2f2;
      color #333
    .chanpinshang-list-titleName
      display flex
      align-items center
      justify-content space-between
      line-height 36px
      color #333
      font-size 24px
      margin-bottom 18px
      box-sizing border-box
      p
        font-size 16px
        padding-right 30px
</style>
